import Mock from 'mockjs'

// 网络质量-网络速率排名数据
export const mockNWqualityRank = () => {
    Mock.mock(/\/api\/network\/rank/, 'get', (options) => {
      const url = new URL(options.url, window.location.origin)
      const params = Object.fromEntries(url.searchParams)

      // 根据不同的网络质量类型返回不同的数据
      let seriesData
      switch(params.networkQuality) {
        case '上行速率':
          seriesData = [
            [900, 850, 800, 780, 700, 650, 600, 500, 430, 400],    // ALL数据（三个运营商的平均值）
            [850, 800, 750, 730, 650, 600, 550, 450, 380, 350],    // CMCC数据
            [800, 750, 700, 680, 600, 550, 500, 400, 330, 300],    // CUCC数据
            [750, 700, 650, 630, 550, 500, 450, 350, 280, 250]     // CTCC数据
          ]
          break
        case '延迟':
          seriesData = [
            [27, 29, 31, 33, 36, 39, 41, 43, 46, 49],    // ALL数据（三个运营商的平均值）
            [25, 28, 30, 32, 35, 38, 40, 42, 45, 48],    // CMCC数据
            [28, 30, 32, 35, 38, 40, 42, 45, 48, 50],    // CUCC数据
            [30, 32, 35, 38, 40, 42, 45, 48, 50, 52]     // CTCC数据
          ]
          break
        default: // 下行速率
          seriesData = [
            [1200, 1150, 1050, 1000, 870, 820, 770, 670, 600, 570],    // ALL数据（三个运营商的平均值）
            [1150, 1100, 1000, 980, 850, 800, 750, 650, 580, 550],     // CMCC数据
            [1100, 1050, 950, 930, 800, 750, 700, 600, 530, 500],      // CUCC数据
            [1050, 1000, 900, 880, 750, 700, 650, 550, 480, 450]       // CTCC数据
          ]
      }

      return {
        code: 200,
        message: 'success',
        data: {
          legends: ['ALL', 'CMCC', 'CUCC', 'CTCC'],  // 添加 ALL 到图例
          xaxisData: ['四川省', '贵州省', '湖南省', '河南省', '上海市', '江苏省', '山东省', '黑龙江', '江西省', '湖北省'],
          seriesData
        }
      }
    })
  }


  // 网络质量统计数据
  export const mockNetworkQuality = () => {
    console.log('Registering mock for network quality')

  Mock.mock(/\/api\/network\/quality/, 'get', () => {
      // 模拟后端返回的数据格式
      return {
        code: 200,
        message: 'success',
        data: {
          legends: ['CMCC', 'CUCC', 'CTCC'],
          xAxisData: ['4G', '3G', '2G'],
          seriesData: [
            // CMCC 数据
            [4000, 3200, 2200],
            // CUCC 数据
            [3800, 3000, 2000],
            // CTCC 数据
            [3600, 2800, 1800]
          ]
        }
      }
    })
    /*
    Mock.mock(/\/api\/network\/quality/, 'get', (options) => {
      console.log('Mock intercepted request:', options)
      const url = new URL(options.url, window.location.origin)
      const networkQuality = url.searchParams.get('networkQuality')
      console.log('Network quality param:', networkQuality)

      // 根据不同的网络质量类型返回不同的数据
      let seriesData
      let unit

      switch(networkQuality) {
        case '上行速率':
          seriesData = [
            [850, 650, 450],    // CMCC数据
            [800, 600, 400],    // CUCC数据
            [750, 550, 350]     // CTCC数据
          ]
          unit = 'Mbps'
          break
        case '延迟':
          seriesData = [
            [25, 35, 45],    // CMCC数据
            [28, 38, 48],    // CUCC数据
            [30, 40, 50]     // CTCC数据
          ]
          unit = 'ms'
          break
        default: // 下行速率
          seriesData = [
            [4000, 3200, 2200],    // CMCC数据
            [3800, 3000, 2000],    // CUCC数据
            [3600, 2800, 1800]     // CTCC数据
          ]
          unit = 'Mbps'
      }

      const response = {
        code: 200,
        message: 'success',
        data: {
          legends: ['CMCC', 'CUCC', 'CTCC'],
          xaxisData: ['4G', '3G', '2G'],
          seriesData,
          unit
        }
      }
      console.log('Mock response:', response)
      return response
    })
    */
  }

// 网络流量跟踪数据
export const mockNetworkTrafficTrack = () => {
  Mock.mock(/\/api\/network\/traffic\/track/, 'get', (options) => {
    return {
      code: 200,
      message: 'success',
      data: {
        legends: ['ALL', 'CMCC', 'CTCC', 'CUCC'],
        xaxisData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        seriesData: [
          [820, 932, 901, 934, 1290, 1330, 1320],
          [420, 532, 501, 534, 690, 730, 720],
          [220, 332, 301, 334, 390, 330, 320],
          [120, 132, 101, 134, 90, 230, 210],
        ],
      },
    }
  })
}

// 网络质量统计数据
export const mockNetworkQualityStats = () => {
  Mock.mock(/\/api\/network\/quality\/stats/, 'get', (options) => {
    return {
      code: 200,
      message: 'success',
      data: {
        locations: ['北京', '上海', '广州', '深圳', '杭州', '南京', '武汉', '成都', '重庆', '西安'],
        operatorData: {
          cmcc: [320, 302, 301, 334, 390, 330, 320, 330, 320, 302],  // 移动数据最高
          ctcc: [220, 182, 191, 234, 290, 230, 220, 230, 220, 182],  // 电信次之
          cucc: [120, 132, 101, 134, 190, 130, 120, 130, 120, 132],  // 联通最低
        }
      }
    }
  })
}
